package classify

import (
	"news_for_deepseek_interface/controller"
	"news_for_deepseek_interface/dto"
	classifyDto "news_for_deepseek_interface/dto/admin/classify"
	classifyService "news_for_deepseek_interface/service/admin/classify"

	"github.com/gin-gonic/gin"
)

func List(c *gin.Context) {
	typeQuery := c.Query("type")

	//1. 参数绑定
	var params classifyDto.ListRequest
	if err := c.ShouldBindQuery(&params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//2. 验证参数
	if err := dto.Validate(params); err != nil {
		controller.Fail(c, controller.ParamsError, err.Error())
		return
	}

	//4. 调用服务层处理登录逻辑
	response, err := classifyService.List(params, typeQuery)
	if err != nil {
		controller.Fail(c, controller.BusinessError, err.Error())
		return
	}

	controller.Success(c, response)
}
